package cn.liumouren.tool.security.autoconfigure;

import cn.liumouren.tool.security.autoconfigure.component.SecurityHolder;
import cn.liumouren.tool.security.core.DlFilterRegistry;
import cn.liumouren.tool.security.core.DlInterceptorRegistry;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

/**
 * <p>注意: @AutoConfigureXxx, @Order...等等注解只会改变beanDefinition的装配顺序, 不会改变创建bean的顺序
 * bean的创建顺序是由<strong>各个bean之间依赖关系</strong>决定 !!!
 *
 * @author daniel liu
 */
@Configuration
@EnableConfigurationProperties(SecurityProperties.class)
@ComponentScan/*("cn.liumouren.tool.security.autoconfigure")*/
@ConditionalOnProperty(value = "dl.security.enable", havingValue = "true", matchIfMissing = true)
public class DlSecurityAutoConfiguration {

    @Bean
    public SecurityHolder securityHolder(DlFilterRegistry dlFilterRegistry, DlInterceptorRegistry dlInterceptorRegistry) {
        SecurityHolder securityHolder = new SecurityHolder();

        securityHolder.setFilterRegistry(dlFilterRegistry);
        securityHolder.setInterceptorRegistry(dlInterceptorRegistry);
        securityHolder.setEnable(true);

        return securityHolder;
    }

}
